$(function () {
    var pageid = 1
    var pageMax

    init()

    function init() {
        getlistData()
        paging()
    }

    function getlistData(pageid) {
        $.ajax({
            url: "http://193.112.55.79:9090/api/getmoneyctrl",
            data: {
                pageid: pageid ? pageid : 1
            },
            success: (res) => {
                console.log(res);
                
                pageMax = res.totalCount
                let data = res.result
                let html = template('savelist', data)
                $('.mm_savemoe').html(html)
                
            }
        })
    }


    //添加分页点击事件
    function paging(pageMax) {
        $('.mui-pager').on('tap','.down',() => {            
            if (pageid >= Math.ceil(pageMax / 10)) {
                mui.toast('已经没有了喔')
                return
            }
            ++pageid            
            $.ajax({
                url: "http://193.112.55.79:9090/api/getmoneyctrl",
                data: {
                    pageid: pageid ? pageid : 1
                },
                success: (res) => {
                    pageMax = res.totalCount
                    let data = res.result
                    let html = template('savelist', data)
                    $('.mm_savemoe').html(html)
                }
            })

        })
        $('.mui-pager').on('tap','.up', () => {
            if (pageid <= 1) {
                mui.toast('这边也没有了喔')
                return
            }
            pageid--            
            $.ajax({
                url: "http://193.112.55.79:9090/api/getmoneyctrl",
                data: {
                    pageid: pageid ? pageid : 1
                },
                success: (res) => {
                    pageMax = res.totalCount
                    let data = res.result
                    let html = template('savelist', data)
                    $('.mm_savemoe').html(html)
                    console.log(pageid);
                }
            })

        })
    }


    //动态生成分页按钮
    function saveId(pageid) {
        console.log(pageid);
        let saveidData = ''
        for (let i = 1; i <= pageid; i++) {
            let data = `<option class="kil" value="${i}">第${i}页</option>`            
            saveidData +=data
        }
        console.log(saveidData);
        $('.listId').html(saveidData)
        
    }
    

})